package com.xingu.xg.controller;

import com.xingu.xg.common.consts.ComRT;
import com.xingu.xg.common.consts.ComResult;
import com.xingu.xg.domain.TreeNode;
import com.xingu.xg.dto.AddNodeQuery;
import com.xingu.xg.dto.CopyNodeQuery;
import com.xingu.xg.dto.DeleteNodeQuery;
import com.xingu.xg.service.TreeNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * @title MyDemoController
 * @description <TODO description class purpose>
 * @author liyanzhen
 * @version
 * @create 2025/4/16 2:29
 **/
@Api(tags = "树节点操作接口")
@RestController
@RequestMapping("/demo")
public class MyDemoController {
    @Autowired
    TreeNodeService treeNodeService;

    /**
     * 查询所有/需要前端组装成树
     */
    @ApiOperation("查询所有树节点")
    @RequestMapping("/getAll")
    public ComResult<List<TreeNode>> getAll(){
        return ComRT.success(treeNodeService.list());
    }

    /**
     * 向上向下创建
     *
     */
    @ApiOperation("创建树节点")
    @RequestMapping("/create")
    public ComResult create(@RequestBody AddNodeQuery addNodeQuery){
        treeNodeService.create(addNodeQuery);
        return ComRT.success();
    }

    /**
     * 拷贝
     * @param copyNodeQuery
     * @return
     */
    @ApiOperation("拷贝树节点")
    @RequestMapping("/copy")
    public ComResult copy(@RequestBody CopyNodeQuery copyNodeQuery){
        treeNodeService.copy(copyNodeQuery);
        return ComRT.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation("批量删除树节点")
    @RequestMapping("/deleteBatch")
    public ComResult deleteBatch(@RequestBody DeleteNodeQuery deleteNodeQuery){
        treeNodeService.deleteBatch(deleteNodeQuery);
        return ComRT.success();
    }

}
